import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;

public class StreamConsumer {

  public StreamConsumer() throws Exception {

    DefaultHttpClient httpclient = new DefaultHttpClient();

    httpclient.getCredentialsProvider().setCredentials(
        new AuthScope("api.twitter.com", 80),
        new UsernamePasswordCredentials("dtii", "$Turner01"));

    HttpGet httpget = new HttpGet("http://api.twitter.com/1/statuses/home_timeline.xml");
    
    /*
    ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
      public String handleResponse(HttpResponse resp)
          throws ClientProtocolException, IOException {

        BufferedReader r = new BufferedReader(new InputStreamReader(
            resp.getEntity().getContent(), "US-ASCII"));
        while (true)
          System.out.println(r.readLine());
      }
    };

    httpclient.execute(httpget, responseHandler);
    */
    HttpResponse response=null;
    HttpContext localContext = new BasicHttpContext();
    
    response = httpclient.execute(httpget,localContext);
    
    HttpEntity entity = response.getEntity();
    
    if (entity != null) {
      System.out.println(EntityUtils.toString(entity));
    } 
    

  }

  public static void main(String[] args) {

    try {
      StreamConsumer consumer = new StreamConsumer();
    } catch (Exception e) {
      e.printStackTrace();
    }

  }

}